/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package tju.mic.utils;

/**
 *
 * @author tjusnow
 */
public class IntUtils {

    public static byte[] intToByte(int a) {
        byte bt[] = new byte[4];
        bt[0] = (byte) ((a >> 0 * 8) & 0xff);
        bt[1] = (byte) ((a >> 1 * 8) & 0xff);
        bt[2] = (byte) ((a >> 2 * 8) & 0xff);
        bt[3] = (byte) ((a >> 3 * 8) & 0xff);
        return bt;
    }

    public static int byteToInt(byte[] a) {
        System.out.println((int) a[0]);  //这里输出的是-49
        System.out.println((int) (a[0] & 0xff));//这里输出是207
        int rs0 = (int) ((a[0] & 0xff) << 0 * 8);
        int rs1 = (int) ((a[1] & 0xff) << 1 * 8);
        int rs2 = (int) ((a[2] & 0xff) << 2 * 8);
        int rs3 = (int) ((a[3] & 0xff) << 3 * 8);
        int result = rs0 + rs1 + rs2 + rs3;
        return result;
    }

}
